home *** CD-ROM | disk | FTP | other *** search
- /*
- File: OrdColl.h
-
- Contains: Definition of class OrderedCollection
-
- Owned by: Richard Rodseth
-
- Copyright: © 1993 - 1995 by Apple Computer, Inc., all rights reserved.
-
-
- In Progress:
-
- */
-
- #ifndef _ORDCOLL_
- #define _ORDCOLL_
-
- #ifndef _ODTYPES_
- #include "ODTypes.h"
- #endif
-
- #ifndef _PLFMDEF_
- #include "PlfmDef.h"
- #endif
-
- #ifndef _LINKLIST_
- #include "LinkList.h"
- #endif
-
- #ifndef _ODMEMORY_
- #include "ODMemory.h"
- #endif
-
- //==============================================================================
- // Theory of Operation
- //==============================================================================
-
- // OrdereCollection is an ordered collection of elements of type void* (since
- // we can't use templates)
- // Duplicates are allowed.
-
- //==============================================================================
- // Constants
- //==============================================================================
-
- //==============================================================================
- // Scalar Types
- //==============================================================================
-
- typedef void* ElementType;
-
- //=====================================================================================
- // Classes defined in this interface
- //=====================================================================================
-
- class OrderedCollection; // An ordered (not sorted) collection of ElementTypes
- class OrderedCollectionIterator;
-
- //=====================================================================================
- // Classes used by this interface
- //=====================================================================================
-
- class ValueLink; // A link plus a value of type ElementType.
-
- //=====================================================================================
- // Global Variables
- //=====================================================================================
-
- //=====================================================================================
- // Class ValueLink - Definition
- //=====================================================================================
-
- class ValueLink : public Link {
-
- public:
- ValueLink(ElementType value);
- ODVMethod ~ValueLink();
- ODNVMethod ElementType GetValue() { return fValue;}
- ODNVMethod void SetValue(ElementType v) { fValue = v;}
-
- private:
- ElementType fValue;
- };
-
- //=====================================================================================
- // Class OrderedCollection
- //=====================================================================================
-
- class OrderedCollection
- {
-
- public:
-
- OrderedCollection();
- OrderedCollection(ODMemoryHeapID where);
- virtual ~OrderedCollection();
-
- ODNVMethod ODULong Count() const { return fImplementation.Count(); };
-
- ODVMethod void AddFirst(ElementType element);
- ODVMethod void AddLast(ElementType element);
- ODVMethod void AddBefore(ElementType existing, ElementType tobeadded);
- ODVMethod void AddAfter(ElementType existing, ElementType tobeadded);
-
- ODVMethod ElementType After(ElementType existing) const;
- ODVMethod ElementType Before(ElementType existing) const;
-
- ODVMethod ElementType First() const;
- // Returns kODNULL if there is no first element.
- ODVMethod ElementType Last() const;
-
- ODVMethod ElementType RemoveFirst();
- // Don't call if there are no elements. Crash will result.
- ODVMethod ElementType RemoveLast();
- ODVMethod void RemoveAll();
-
- // Called from the destructor. Removes all elements, deleting the links
- // Does not delete the elements themselves
-
- ODVMethod void DeleteAll();
-
- // Removes and deletes all elements
-
- ODVMethod ODBoolean Remove(ElementType existing);
- // Returns true if existing was actually removed.
-
- ODVMethod ODBoolean Contains(ElementType existing) const;
-
- ODVMethod OrderedCollectionIterator* CreateIterator();
-
- ODNVMethod ODMemoryHeapID GetHeap() const;
-
- protected:
- ODVMethod ValueLink* CreateNewLink(ElementType value) const;
- ODVMethod ODBoolean ElementsMatch(ElementType v1,ElementType v2) const;
- // Does a pointer comparison by default
-
- private:
- LinkedList fImplementation;
- ODMemoryHeapID fHeap; // if kODNULL, use default heap.
-
- friend class OrderedCollectionIterator;
- friend class ListIterator;
- };
-
- inline ODMemoryHeapID OrderedCollection::GetHeap() const
- {
- return fHeap;
- }
-
-
- //=====================================================================================
- // Class OrderedCollectionIterator
- //=====================================================================================
-
- class OrderedCollectionIterator {
- public:
- OrderedCollectionIterator(OrderedCollection* collection);
- ~OrderedCollectionIterator();
- ElementType First();
- ElementType Next();
- ElementType Last();
- ElementType Previous();
- ODBoolean IsNotComplete();
- void RemoveCurrent();
-
- private:
- OrderedCollection* fCollection;
- LinkedListIterator fImplementation;
- };
-
- #endif // _ORDCOLL_